import S from 'ant-design-vue/es/select'
import { commonProps } from '../_util/util'

export default {
  data() {
    return {
    }
  },
  props: Object.assign({}, S.props, commonProps, {
    initialValue: {
      type: String,
      default: '',
      required: false
    }
  }),
  watch: {

  },
  created() {
    this.formItemId && this.form.getFieldDecorator(this.formItemId, this.formOptions)
  },
  methods: {
    handleChange(value) {
      console.log(value)
      this.formItemId && this.form.setFieldsValue({ [this.formItemId]: value })
    }
  },
  render() {
    const { options, initialValue, value, setStyle, formOptions: { initialValue: initialValue2 }, ...rest } = this.$props
    var restObj = rest
    for (var key in restObj) {
      if (restObj[key] === undefined) { delete restObj[key] }
    }
    return (
      <a-select style={setStyle} {...{ props: { ...restObj, defaultValue: initialValue2 || initialValue }}} onChange= {this.handleChange} >
        {options.map(
          ({
            key,
            title,
            value,
            txt,
            disabled = false,
            ...rest
          }) => (
            <a-select-option
              disabled={disabled}
              value={value}
              title={title}
              {...rest}
            >
              {txt || title}
            </a-select-option>
          )
        )}
      </a-select>
    )
  }
}
